package com.jackiechan.day14;

import java.util.*;

public class Test_Map {
    public static void main(String[] args) {
//        display();
//        show();
//        play();

    }



    private static void display() {
        Map<Integer,String> map = new HashMap<>();
        map.put(1,"成龙");
        map.put(2,"杰克");
        map.put(4,"蒙毅");
        System.out.println(map);
        // 传递引用
        Map<Integer,String> map1 = map;
        System.out.println(map.hashCode());
        System.out.println(map.get(1));
        System.out.println(map.put(1,"仕龙"));
        System.out.println(map.put(3,"仕龙"));
        System.out.println(map.size());
        System.out.println(map);
        System.out.println(map.hashCode());
        System.out.println(map1);
        System.out.println(map == map1);
        System.out.println(map.equals(map1));
        System.out.println(map.isEmpty());
        System.out.println(map.remove(3));
        System.out.println(map);

        {
            System.out.println(map.values());
            Collection<String> values = map.values();
            Iterator<String> iterator = values.iterator();
            while (iterator.hasNext()){
                System.out.print(iterator.next()+"  ");
            }
            System.out.println();
            for (String s :values) {
                System.out.print(s+" ");
            }
            System.out.println();
        }

        {
            Set<Integer> keys = map.keySet();
            System.out.println(keys);
            for (Integer i :keys) {
                System.out.print(i+"==>"+map.get(i)+" ");
            }
            System.out.println();
        }

        {
            Set<Map.Entry<Integer, String>> entryset = map.entrySet();
            System.out.println(entryset);
            for (Map.Entry<Integer, String> o :entryset) {
                Integer key = o.getKey();
                String value = o.getValue();
                System.out.print(key+"-->"+value+" ");
            }
            System.out.println();
        }

    }

    private static void show() {
        Map<Integer,String> map = new HashMap<>();
        map.put(1,"成龙");
        map.put(2,"杰克");
        map.put(4,"蒙毅");
        Map<Integer,Object> map1 = new HashMap<>();
        map1.put(1,map);
        map1.put(2, map);
        System.out.println(map1);

        Map<Integer,Object> map2 = new HashMap<>();
        map2.put(1,map1);
        map2.put(2, map1);
        System.out.println(map2);

        A a = new A();
        Map<Integer,A> map3 = new HashMap<>();
        map3.put(1,a);
        map3.put(2,a);
        System.out.println(map3);

        System.out.println(map1.equals(map2));
    }

    public static void play(){
        A.B a = new A().new B();
        System.out.println(a.str);
    }
}

class A{

    class B{
        String str = "A 的内部类 B";
    }

}